package com.hanhanxiaochong.zhongxiangchuanmei.presenter;

import com.hanhanxiaochong.zhongxiangchuanmei.bean.NearByShopBean;
import com.hanhanxiaochong.zhongxiangchuanmei.config.HttpPostService;
import com.hanhanxiaochong.zhongxiangchuanmei.presenter.base.BasePresenter;
import com.hanhanxiaochong.zhongxiangchuanmei.view.iview.NearByShopView;
import com.trello.rxlifecycle.components.support.RxAppCompatActivity;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.BaseApi;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.BaseObserver;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.ResponseBase;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.http.RetrofitSource;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by RockPhoenix on 2018/5/22.
 */

public class NearByShopPresenter extends BasePresenter<NearByShopView> {

    public NearByShopPresenter(NearByShopView iView) {
        super(iView);
    }

    @Override
    public void startPost(RxAppCompatActivity rxAppCompatActivity, BaseApi baseApi) {

    }

    @Override
    public void startPost(RxAppCompatActivity rxAppCompatActivity, BaseApi baseApi, int state) {

    }

    public void getShopList(String sortType, String lat, String lng, String page, String name, String city) {
        Map<String, String> map = new HashMap<>();
        map.put("type", sortType);
        map.put("page", page);
        map.put("size", "10");
        map.put("lat", lat);
        map.put("lng", lng);
        if (name != null)
            map.put("name", name);
        map.put("city", city);
        if (name != null)
            map.put("name", name);
        if (city != null)
            map.put("city", city);
        addSubscription(RetrofitSource.createApi(HttpPostService.class).nearbyShop(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<ResponseBase<List<NearByShopBean>>>(iView) {
                    @Override
                    public void onSuccess(ResponseBase<List<NearByShopBean>> response) {
                        iView.setNearby(response.getData());
                    }
                }));
    }
}
